package com.gdones.wms.bus.record.controller;


import com.gdones.common.core.annotations.MySysLog;
import com.gdones.common.core.annotations.MySysLogOpration;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyResult;
import com.gdones.wms.bus.record.dto.RecordDto;
import com.gdones.wms.bus.record.dto.WmsRecord;
import com.gdones.wms.bus.record.service.IWmsRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author GaoJingBo
 * @since 2023-05-08
 */
@RestController
@RequestMapping("/record")
@Slf4j
@Api(tags = "物资台账")
public class WmsRecordController {

    @Resource(name = "wmsRecordServiceImpl")
    private IWmsRecordService wmsRecordService;

    @GetMapping("/pages")
    @ApiOperation("物资台账-台账分页信息")
    @MySysLog(modelName="物资台账",methodDesc = "台账分页信息",methodType = MySysLogOpration.GET)
    public MyResult pages(WmsRecord record, MyPageBand pageBand){

        log.debug("--物资台账：分页信息");
        MyResult result = new MyResult();

        try {
            result = wmsRecordService.pages(record,pageBand);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资台账-台账分页信息-异常");
        }
        return result;
    }

    @GetMapping("/list")
    @ApiOperation("物资台账-台账列表信息（不分页）")
    @MySysLog(modelName="物资台账",methodDesc = "台账列表信息（不分页）",methodType = MySysLogOpration.GET)
    public MyResult list(WmsRecord record){

        log.debug("--物资台账：台账列表信息（不分页）");
        MyResult result = new MyResult();

        try {
            result = wmsRecordService.list(record);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资台账-台账列表信息（不分页）-异常");
        }
        return result;
    }

    @GetMapping("/getLifeList")
    @ApiOperation("物资台账-获取物资生命周期记录根据物资id")
    @MySysLog(modelName="物资台账",methodDesc = "获取物资生命周期记录根据物资id",methodType = MySysLogOpration.GET)
    public MyResult getLifeList(String recordID){

        log.debug("--物资台账：获取物资生命周期记录根据物资id");
        MyResult result = new MyResult();

        try {
            result = wmsRecordService.getLifeList(recordID);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资台账-获取物资生命周期记录根据物资id-异常");
        }
        return result;
    }

    @GetMapping("/getByID")
    @ApiOperation("物资台账-获取物资信息根据物资id")
    @MySysLog(modelName="物资台账",methodDesc = "获取物资信息根据物资id",methodType = MySysLogOpration.GET)
    public MyResult getByID(String recordID){

        log.debug("--物资台账：获取物资信息根据物资id");
        MyResult result = new MyResult();

        try {
            result = wmsRecordService.getByID(recordID);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资台账-获取物资信息根据物资id-异常");
        }
        return result;
    }


    @PostMapping("/add")
    @ApiOperation("物资台账-新增台账")
    @MySysLog(modelName="物资台账",methodDesc = "新增台账",methodType = MySysLogOpration.POST)
    public MyResult add(@RequestBody  RecordDto dto){

        log.debug("--物资台账：分页信息");
        MyResult result = new MyResult();

        try {
            result = wmsRecordService.add(dto);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资台账-新增台账-异常");
        }
        return result;
    }

    @PutMapping("/update")
    @ApiOperation("物资台账-修改台账")
    @MySysLog(modelName="物资台账",methodDesc = "修改台账",methodType = MySysLogOpration.PUT)
    public MyResult update(@RequestBody RecordDto dto){

        log.debug("--物资台账：修改台账");
        MyResult result = new MyResult();

        try {
            result = wmsRecordService.update(dto);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资台账-修改台账-异常");
        }
        return result;
    }


    @DeleteMapping("/deletes")
    @ApiOperation("物资台账-删除台账")
    @MySysLog(modelName="物资台账",methodDesc = "删除台账",methodType = MySysLogOpration.DELETE)
    public MyResult deletes(String ids){

        log.debug("--物资台账：删除台账");
        MyResult result = new MyResult();

        try {
            result = wmsRecordService.deletes(ids);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资台账-删除台账-异常");
        }
        return result;
    }

    @PostMapping("/outRecord")
    @ApiOperation("物资台账-出库物资")
    @MySysLog(modelName="物资台账",methodDesc = "出库物资",methodType = MySysLogOpration.POST)
    public MyResult outRecord(@RequestBody RecordDto dto){

        log.debug("--物资台账：出库物资");
        MyResult result = new MyResult();

        try {
            result = wmsRecordService.outRecord(dto);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("物资台账-出库物资-异常");
        }
        return result;
    }

}
